package com.cssw.fyzb.busi.api.acct;


import com.cssw.fyzb.busi.service.acct.OutAcctService;
import com.cssw.fyzb.core.model.dodb.BankCode;
import com.cssw.fyzb.core.model.dodb.BankCodeCh;
import com.cssw.fyzb.core.model.vo.acct.BankCodeVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


/**
 * @Author: yangyiqun
 * @Date: 2020/7/11 16:25
 */
@Function(description = "查询传化银行编码列表")
@Component
public class ListBankCodeCh implements Action {
    private static final Logger logger = LoggerFactory.getLogger(ListBankCodeCh.class);

    @Autowired
    private OutAcctService outAcctService;

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");

        try {
            List<BankCodeCh> userBankList = outAcctService.listBankCodeCh();
            List<BankCodeVo> bankCodeVos = new ArrayList<>();
            BankCodeVo bankCodeVo = null;
            for (BankCodeCh u : userBankList) {
                bankCodeVo = new BankCodeVo();
                bankCodeVo.setBankCode(u.getBankCode());
                bankCodeVo.setBankName(u.getBankName());
                bankCodeVo.setRemark(u.getRemark());
                bankCodeVos.add(bankCodeVo);
            }
            return Response.success().put("list", bankCodeVos);
        } catch (Exception e) {
            logger.error("", e);
            return Response.fail("获取银行失败");
        }
    }
}
